from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2023-01-09 14:03:23.682702
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 09, Jan, 2023
Time: 14:03:30
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.3657
Nobs: 896.000 HQIC: -51.6635
Log likelihood: 11875.4 FPE: 3.03993e-23
AIC: -51.8476 Det(Omega_mle): 2.75094e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295568 0.048704 6.069 0.000
L1.Burgenland 0.107247 0.033730 3.180 0.001
L1.Kärnten -0.106082 0.018098 -5.862 0.000
L1.Niederösterreich 0.212311 0.070721 3.002 0.003
L1.Oberösterreich 0.077817 0.066797 1.165 0.244
L1.Salzburg 0.251008 0.035816 7.008 0.000
L1.Steiermark 0.032119 0.047019 0.683 0.495
L1.Tirol 0.124928 0.038112 3.278 0.001
L1.Vorarlberg -0.059920 0.032834 -1.825 0.068
L1.Wien 0.068947 0.059629 1.156 0.248
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059486 0.099702 0.597 0.551
L1.Burgenland -0.008258 0.069049 -0.120 0.905
L1.Kärnten 0.048166 0.037048 1.300 0.194
L1.Niederösterreich -0.168899 0.144772 -1.167 0.243
L1.Oberösterreich 0.355676 0.136740 2.601 0.009
L1.Salzburg 0.286711 0.073318 3.911 0.000
L1.Steiermark 0.107530 0.096252 1.117 0.264
L1.Tirol 0.322016 0.078018 4.127 0.000
L1.Vorarlberg 0.024618 0.067213 0.366 0.714
L1.Wien -0.021299 0.122065 -0.174 0.861
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.202574 0.025505 7.942 0.000
L1.Burgenland 0.091843 0.017664 5.199 0.000
L1.Kärnten -0.008828 0.009478 -0.931 0.352
L1.Niederösterreich 0.265224 0.037035 7.161 0.000
L1.Oberösterreich 0.107397 0.034980 3.070 0.002
L1.Salzburg 0.055043 0.018756 2.935 0.003
L1.Steiermark 0.016707 0.024623 0.679 0.497
L1.Tirol 0.100222 0.019958 5.022 0.000
L1.Vorarlberg 0.057057 0.017194 3.318 0.001
L1.Wien 0.113650 0.031226 3.640 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107558 0.026106 4.120 0.000
L1.Burgenland 0.049456 0.018080 2.735 0.006
L1.Kärnten -0.016237 0.009701 -1.674 0.094
L1.Niederösterreich 0.197313 0.037908 5.205 0.000
L1.Oberösterreich 0.271981 0.035804 7.596 0.000
L1.Salzburg 0.118837 0.019198 6.190 0.000
L1.Steiermark 0.101605 0.025203 4.031 0.000
L1.Tirol 0.123979 0.020429 6.069 0.000
L1.Vorarlberg 0.069879 0.017599 3.971 0.000
L1.Wien -0.025198 0.031962 -0.788 0.430
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.140353 0.046767 3.001 0.003
L1.Burgenland -0.053536 0.032389 -1.653 0.098
L1.Kärnten -0.035600 0.017378 -2.049 0.041
L1.Niederösterreich 0.162146 0.067908 2.388 0.017
L1.Oberösterreich 0.128462 0.064141 2.003 0.045
L1.Salzburg 0.292200 0.034391 8.496 0.000
L1.Steiermark 0.035229 0.045149 0.780 0.435
L1.Tirol 0.157793 0.036596 4.312 0.000
L1.Vorarlberg 0.108149 0.031528 3.430 0.001
L1.Wien 0.066478 0.057257 1.161 0.246
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.066599 0.037274 1.787 0.074
L1.Burgenland 0.039233 0.025814 1.520 0.129
L1.Kärnten 0.049534 0.013851 3.576 0.000
L1.Niederösterreich 0.224107 0.054123 4.141 0.000
L1.Oberösterreich 0.262159 0.051120 5.128 0.000
L1.Salzburg 0.061796 0.027410 2.255 0.024
L1.Steiermark -0.005642 0.035984 -0.157 0.875
L1.Tirol 0.158047 0.029167 5.419 0.000
L1.Vorarlberg 0.067894 0.025128 2.702 0.007
L1.Wien 0.076961 0.045634 1.686 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198744 0.044966 4.420 0.000
L1.Burgenland 0.017633 0.031142 0.566 0.571
L1.Kärnten -0.057062 0.016709 -3.415 0.001
L1.Niederösterreich -0.100522 0.065293 -1.540 0.124
L1.Oberösterreich 0.175426 0.061671 2.845 0.004
L1.Salzburg 0.063526 0.033067 1.921 0.055
L1.Steiermark 0.224953 0.043410 5.182 0.000
L1.Tirol 0.477732 0.035187 13.577 0.000
L1.Vorarlberg 0.051479 0.030314 1.698 0.089
L1.Wien -0.050104 0.055052 -0.910 0.363
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148526 0.050468 2.943 0.003
L1.Burgenland 0.000874 0.034952 0.025 0.980
L1.Kärnten 0.067444 0.018754 3.596 0.000
L1.Niederösterreich 0.203651 0.073283 2.779 0.005
L1.Oberösterreich -0.070791 0.069217 -1.023 0.306
L1.Salzburg 0.220453 0.037113 5.940 0.000
L1.Steiermark 0.108857 0.048722 2.234 0.025
L1.Tirol 0.081317 0.039492 2.059 0.039
L1.Vorarlberg 0.128817 0.034023 3.786 0.000
L1.Wien 0.111822 0.061788 1.810 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358272 0.030028 11.931 0.000
L1.Burgenland 0.009909 0.020796 0.476 0.634
L1.Kärnten -0.025341 0.011158 -2.271 0.023
L1.Niederösterreich 0.228366 0.043603 5.237 0.000
L1.Oberösterreich 0.145198 0.041184 3.526 0.000
L1.Salzburg 0.054457 0.022082 2.466 0.014
L1.Steiermark -0.015440 0.028989 -0.533 0.594
L1.Tirol 0.120723 0.023498 5.138 0.000
L1.Vorarlberg 0.072851 0.020243 3.599 0.000
L1.Wien 0.052337 0.036764 1.424 0.155
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039690 0.171555 0.187879 0.174047 0.152842 0.135421 0.071767 0.226252
Kärnten 0.039690 1.000000 0.004748 0.133485 0.027403 0.100203 0.427059 -0.047325 0.103098
Niederösterreich 0.171555 0.004748 1.000000 0.359546 0.179386 0.328002 0.147804 0.199855 0.352490
Oberösterreich 0.187879 0.133485 0.359546 1.000000 0.241819 0.352017 0.195396 0.185376 0.283032
Salzburg 0.174047 0.027403 0.179386 0.241819 1.000000 0.161825 0.148116 0.155193 0.146936
Steiermark 0.152842 0.100203 0.328002 0.352017 0.161825 1.000000 0.174123 0.154101 0.108366
Tirol 0.135421 0.427059 0.147804 0.195396 0.148116 0.174123 1.000000 0.130328 0.174308
Vorarlberg 0.071767 -0.047325 0.199855 0.185376 0.155193 0.154101 0.130328 1.000000 0.027534
Wien 0.226252 0.103098 0.352490 0.283032 0.146936 0.108366 0.174308 0.027534 1.000000